package main

import (
	"fmt"
	"log"
	"strings"
	"unicode"
	"unicode/utf8"
)

func main() {

	var names = "lisi嘿"

	log.Println(names)
	//获取第一个字符
	first, _ := utf8.DecodeRuneInString(names)
	//获取最后一个字符
	last, _ := utf8.DecodeLastRuneInString(names)

	log.Println("第一个字符和最后一个字符分别是:", string(first), string(last))
	str, l := firstAndLastStr("n 我")
	log.Println("|" + str + "|" + l + "|")
	fmt.Printf("%T %T", names, true)

}

// firstAndLastStr 在任意空白分隔符的情况下找到其中第一个字和最后一个字符
func firstAndLastStr(line string) (first, last string) {
	indexFunc := strings.IndexFunc(line, unicode.IsSpace)
	first = line[:indexFunc]

	j := strings.LastIndexFunc(line, unicode.IsSpace)
	_, size := utf8.DecodeRuneInString(line[j:])
	last = line[size+j:]

	fmt.Println(first, last)
	return
}
